1 // Equipo Poncho, Carriel y Ruana
22 template <class T
> string
toStr(const T
&x
)
23 { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
)
25 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS
= 1e-9;
33 int cmp(double x
, double y
= 0, double tol
= EPS
) {
34 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
37 #define INPUT_FILE "edgetown"
50 g1
[i
][j
] = min(g1
[i
][j
], g1
[i
][k
] + g1
[k
][j
]);
51 g2
[i
][j
] = min(g2
[i
][j
], g2
[i
][k
] + g2
[k
][j
]);
57 vector
<int> gg1
[MAXN
], gg2
[MAXN
];
60 void bfs(int start
, vector
<int> g
[MAXN
]) {
61 For(i
, 0, n
) dist
[i
] = oo
;
69 for (int k
= 0; k
< g
[u
].size(); ++k
) {
72 if (dist
[v
] < oo
) continue;
73 dist
[v
] = dist
[u
] + 1;
79 bool equal(long long a
, long long b
) {
82 if (g2
[i
][j
] >= oo
) return false;
83 long long now
= g2
[i
][j
];
84 long long cota
= g1
[i
][j
] * a
+ b
;
86 //printf("From %d to %d: now = %d, cota = %d, old = %d\n", i, j, (int)now, (int)cota, g1[i][j]);
95 freopen(INPUT_FILE
".in", "r", stdin
);
98 string s
; getline(cin
, s
);
100 For (i
, 0, n
) For(j
, 0, n
) g1
[i
][j
] = g2
[i
][j
] = oo
;
101 For (i
, 0, n
) gg1
[i
].clear(), gg2
[i
].clear();
103 for (int i
= 0; i
< n
; ++i
) {
106 int first
; sin
>> first
; first
--;
108 while (sin
>> other
) {
110 g1
[first
][other
] = 1;
111 gg1
[first
].push_back(other
);
115 for (int i
= 0; i
< n
; ++i
) {
118 int first
; sin
>> first
; first
--;
120 while (sin
>> other
) {
122 g2
[first
][other
] = 1;
123 gg2
[first
].push_back(other
);
126 For(i
, 0, n
) g1
[i
][i
] = g2
[i
][i
] = 0;
130 if (a
== 0 and b
== 0 and n
> 1) {
135 //puts("G1"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g1[i][j]); } puts(""); } puts("");
136 //puts("G2"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g2[i][j]); } puts(""); } puts("");